package com.santu.edu.supporter.biz.user.controller;

import com.santu.edu.supporter.biz.user.pojo.dto.UserAddressDTO;
import com.santu.edu.supporter.biz.user.pojo.params.UserAddressAddParam;
import com.santu.edu.supporter.biz.user.pojo.params.UserAddressUpdateParam;
import com.santu.edu.supporter.biz.user.service.UserAdressService;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @author 12158
 */
@RestController
@Validated
@RequiredArgsConstructor
@RequestMapping("user/address")
public class UserAddressController {

    private final UserAdressService userAdressService;

    @PostMapping("add")
    public Boolean addUserAddress(@RequestBody @Valid UserAddressAddParam addParam) {
        return userAdressService.addUserAddress(addParam);
    }

    @PostMapping("update")
    public Boolean updateUserAddress(@RequestBody @Valid UserAddressUpdateParam updateParam) {
        return userAdressService.updateUserAddress(updateParam);
    }

    @PostMapping("remove")
    public Boolean removeUserAddress(@NotBlank(message = "addressId不能为空") String addressId) {
        return userAdressService.removeUserAddress(addressId);
    }


    @GetMapping("get/address/by/userId")
    public List<UserAddressDTO> getUserAddressList() {
        return userAdressService.getUserAddressList();
    }


}
